<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.myproject.*" %>

<%@ page import="java.util.List" %>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	</head>	
		<h1>Series Research</h1>
	<%
		String filetype = request.getParameter("fileType")==null?"":request.getParameter("fileType");
	%>
	<body>
	
	<% String content = request.getParameter("content"); %>	
			
	<table border=1 cellpadding=2 cellspacing =0 width=500>
		<tr align=center>
			<td>Title</td>
			<td>Caption</td>
			<td>ContentType</td>
		</tr>
<%
	List<?> alist = null;

	if("audio".equals(filetype))
	{
		AudioUploadDAO dao = new AudioUploadDAO();
		alist = dao.list();
	}
	else if("video".equals(filetype))
	{
		VideoUploadDAO dao = new VideoUploadDAO();
		alist = dao.list();			
	}
	else if("image".equals(filetype))
	{
		PictureUploadDAO dao = new PictureUploadDAO();
		alist = dao.list();			
	}
	else if("book".equals(filetype))
	{
		BookUploadDAO dao = new BookUploadDAO();
		alist = dao.list();			
	}
	else 
	{
		UploadDAO dao = new UploadDAO();
		alist = dao.list();			
	}

	String title = "";
	String caption = "";
	String findCaption = "(?i).*" + content + ".*";
	String contenttype = "";
	long id = 0; 
	long parentid = 0;
	
	if(alist.size()>0)
	{
		for(int i=0; i<alist.size(); i++)
		{
			if(alist.get(i) instanceof UploadDTO
					&&	((UploadDTO)alist.get(i)).getCaption().matches(findCaption))
			{
				title = ((UploadDTO)alist.get(i)).getTitle();
				caption = ((UploadDTO)alist.get(i)).getCaption();
				contenttype = ((UploadDTO)alist.get(i)).getContentType();	
%>
				<tr>	
					<td>&nbsp;<%=title%></td>
					<td>&nbsp;<%=caption%></td>
					<td>&nbsp;<%=contenttype%></td>
				</tr>
<%				
			}
			else if(alist.get(i) instanceof AudioUploadDTO
					&& ((AudioUploadDTO)alist.get(i)).getCaption().matches(findCaption))
			{
				title = ((AudioUploadDTO)alist.get(i)).getTitle();
				caption = ((AudioUploadDTO)alist.get(i)).getCaption();
				contenttype = ((AudioUploadDTO)alist.get(i)).getContentType();
%>
				<tr>	
					<td>&nbsp;<%=title%></td>
					<td>&nbsp;<%=caption%></td>
					<td>&nbsp;<%=contenttype%></td>
				</tr>
<%				
				
			}
			else if(alist.get(i) instanceof VideoUploadDTO
					&& ((VideoUploadDTO)alist.get(i)).getCaption().matches(findCaption))
			{
				title = ((VideoUploadDTO)alist.get(i)).getTitle();
				caption = ((VideoUploadDTO)alist.get(i)).getCaption();
				contenttype = ((VideoUploadDTO)alist.get(i)).getContentType();
%>
				<tr>	
					<td>&nbsp;<%=title%></td>
					<td>&nbsp;<%=caption%></td>
					<td>&nbsp;<%=contenttype%></td>
				</tr>
<%				
				
			}
			else if(alist.get(i) instanceof PictureUploadDTO
					&& ((PictureUploadDTO)alist.get(i)).getCaption().matches(findCaption))
			{
				title = ((PictureUploadDTO)alist.get(i)).getTitle();
				caption = ((PictureUploadDTO)alist.get(i)).getCaption();
				contenttype = ((PictureUploadDTO)alist.get(i)).getContentType();
%>
				<tr>	
					<td>&nbsp;<%=title%></td>
					<td>&nbsp;<%=caption%></td>
					<td>&nbsp;<%=contenttype%></td>
				</tr>
<%				
				
			}
			else if(alist.get(i) instanceof BookUploadDTO
					&& ((BookUploadDTO)alist.get(i)).getCaption().matches(findCaption))
			{
				title = ((BookUploadDTO)alist.get(i)).getTitle();
				caption = ((BookUploadDTO)alist.get(i)).getCaption();
				contenttype = ((BookUploadDTO)alist.get(i)).getContentType();
%>
				<tr>	
					<td>&nbsp;<%=title%></td>
					<td>&nbsp;<%=caption%></td>
					<td>&nbsp;<%=contenttype%></td>
				</tr>
<%				
			}
		}
	
	}
	else
	{	
%>
			<tr>	
				<td colspan=5 align=center>no data</td>	

			</tr>
<%
	}
%>	
		</table>
				
			<table  height=10 >
				<tr align=center>
					<td></td>	
				</tr>
			</table>
			<a href="index.html">main</a>		<a href="list.jsp">list</a>
	</form>
	</body>	
</html>